#!/usr/bin/python
# -*- coding: utf-8 -*-
#Author: Onur ASLAN
#Mail : hata.pindir@gmail.com 


from PyQt4 import QtCore
from PyQt4 import QtGui
from Ui_MainWindow import Ui_MainWindow
from urlparse import urlparse, parse_qs
import getpass
import os

def watchVideo(self):
	self.widget_6.show()
	url = str(self.lineEdit.text())
	if url == "":
		dosya = open("/home/"+getpass.getuser()+"/.pindir_watchvideoembed.html", "w")
		dosya.write(unicode("Adres Yok (Address None)"))
		dosya.close()
	if url != "":					
		url_str = urlparse(url)
		url_qstr = parse_qs(url_str.query)
		video_name = url_qstr["v"][0]	
		kod = "<iframe width='425' height='349' src='http://www.youtube.com/embed/"+video_name+"' frameborder='0' allowfullscreen></iframe>"
		dosya = open("/home/"+getpass.getuser()+"/.pindir_watchvideoembed.html", "w")
		dosya.write(kod)
		dosya.close()
		self.webView.setUrl(QtCore.QUrl("/home/"+getpass.getuser()+"/.pindir_watchvideoembed.html"))
